<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        // 基本数据类型:Number、String、Boolean、Null、undefined、Symbol、Bigint(新引入的)
        // 引用数据类型:Object、Array、Function等

        // 对对象而言，它的第一层属性值如果是基本数据类型则完全拷贝一份数据，
        // 如果是引用类型就拷贝内存地址
        // 实现 Object.assign()
        let obj1 = {
            name: 'zhangfan',
            age: {
                value: 18
            }
        }
        let obj2 = Object.assign({}, obj1)
        console.log(obj2) // {name:'zhangfan',age:{value:18}}
        console.log(obj1) // {name:'zhangfan',age:{value:18}}
        obj2.age.value = 28
        console.log(obj2) // {name:'zhangfan',age:{value:28}}
        console.log(obj1) // {name:'zhangfan',age:{value:28}} // 指向同一个内存地址 一变皆变

        // console.log(obj1 === obj2) // false

        obj1.name = 'oupai'
        console.log(obj1) // {name:'oupai',age:{value:28}} // 承接最近的值
        console.log(obj2) // {name:'zhangfan',age:{value:28}} // 承接最近的值

        // 展开语法
        let aaa = {
            name: 'liubei',
            age: {
                value: 10
            }
        }
        let { ...bbb } = aaa
        bbb.name = 'guanyu'
        bbb.age.value = 20
        console.log(bbb) // {name:'guanyu',age:{value:20}} 引用类型变了(地址一致)
        console.log(aaa) // {name:'liubei',age:{value:20}} 引用类型变了(地址一致)

        let b = {
            ...aaa,
            age: {
                value: 100000
            },
            c: {
                value111: 123
            }
        }
        console.log(b) // {name:'liubei',age:{value:100000},c:{value111: 123}}

        // Array.prototype.slice
        const arr1 = [
            'yang',
            {
                value: 123
            }
        ]
        const arr2 = arr1.slice(0) // slice 提取字符串的某个部分 slice(0) 就是全部
        console.log(arr2) // ['yang',{value:123}]
        arr2[1].value = 456
        console.log(arr1) // ['yang',{value:456}]
        console.log(arr2) // ['yang',{value:456}]
        arr2[0] = 'haha'
        console.log(arr2) // ['haha',{value:456}]
        console.log(arr1) // ["yang", {value: 456}]

        const arr3 = [
            'yang',
            {
                value: 123
            }
        ]
        const arr4 = [].concat(arr3)
        console.log(arr4) // ['yang',{value:123}]
        arr4[1].value = 456
        console.log(arr4) // ['yang',{value:456}]
        console.log(arr3) // ['yang',{value:456}]
        arr4[0] = 'haha'
        console.log(arr4) // ['haha',{value:456}]
        console.log(arr3) // ['yang',{value:456}]
    </script>
</head>

<body>

</body>

</html>